﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BFlatCompile.Serializer
{
	internal static class Phase14ConcatenateCodeAndStartLocationLookup
	{
		public static void Do(Compiler compiler, Dictionary<string, Serializer.Buffer> cellsBySignature, Dictionary<string, int> sizeBySignature, Dictionary<string, int> startLocations, Serializer.Buffer byteCode)
		{
			int offset = 0;
			foreach (string signature in cellsBySignature.Keys)
			{
				byteCode.Add(cellsBySignature[signature]);
				startLocations[signature] = offset;
				offset += sizeBySignature[signature];
			}

			byteCode.ResolveTryPushOffsetsIntoAbsoluteAddresses(compiler);
		}
	}
}
